SET TMP_FOLDER=%TEMP%\fight_cancer0101
set WCG_BOINC_EXE=%TMP_FOLDER%\wcg_boinc.exe
mkdir %TMP_FOLDER%

:: Download World Community Grid Windows client from internet
powershell.exe -ExecutionPolicy Bypass -Command (New-Object System.Net.WebClient).DownloadFile('http://www.worldcommunitygrid.org/clients/wcg_boinc_6.10.58_windows_intelx86.exe', '%WCG_BOINC_EXE%')

if %ERRORLEVEL% EQU 0 GOTO INSTALL_WCG

:: Download using cscript
echo "Donwloading using cscript"
:: Create cscript file to download World Community Grid Windows client from internet
set DOWN_CS=%TMP_FOLDER%\down.vbs
echo 'Set your settings > %DOWN_CS%
echo strFileURL = "http://www.worldcommunitygrid.org/clients/wcg_boinc_6.10.58_windows_intelx86.exe" >> %DOWN_CS%
echo strHDLocation = "%WCG_BOINC_EXE%" >> %DOWN_CS%
echo    ' Fetch the file >> %DOWN_CS%
echo     Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP") >> %DOWN_CS%
echo     objXMLHTTP.open "GET", strFileURL, false >> %DOWN_CS%
echo     objXMLHTTP.send() >> %DOWN_CS%
echo     If objXMLHTTP.Status = 200 Then >> %DOWN_CS%
echo       Set objADOStream = CreateObject("ADODB.Stream") >> %DOWN_CS%
echo       objADOStream.Open >> %DOWN_CS%
echo       objADOStream.Type = 1 'adTypeBinary >> %DOWN_CS%
echo       objADOStream.Write objXMLHTTP.ResponseBody >> %DOWN_CS%
echo       objADOStream.Position = 0    'Set the stream position to the start >> %DOWN_CS%
echo       Set objFSO = Createobject("Scripting.FileSystemObject") >> %DOWN_CS%
echo         If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation >> %DOWN_CS%
echo       Set objFSO = Nothing >> %DOWN_CS%
echo       objADOStream.SaveToFile strHDLocation >> %DOWN_CS%
echo       objADOStream.Close >> %DOWN_CS%
echo       Set objADOStream = Nothing >> %DOWN_CS%
echo     End if >> %DOWN_CS%
echo     Set objXMLHTTP = Nothing >> %DOWN_CS%

cscript %DOWN_CS%

:: Install World Community Grid. Do not use screen saver, use protected mode and run as service.
:INSTALL_WCG
%WCG_BOINC_EXE% /S /v"/norestart /qn PROJINIT_AUTH=718018_6a26d3912988249cbdc3cc5caca6646e ENABLESCREENSAVER=0 ENABLEPROTECTEDAPPLICATIONEXECUTION2=1"